package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.VideoDate;
import com.ruoyi.system.service.IVideoDateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 视频数据Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/date")
public class VideoDateController extends BaseController
{
    @Autowired
    private IVideoDateService videoDateService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 查询视频数据列表
     */
    @RequiresPermissions("system:date:list")
    @GetMapping("/list")
    public TableDataInfo list(VideoDate videoDate)
    {
        startPage();
        List<VideoDate> list = videoDateService.selectVideoDateList(videoDate);
        return getDataTable(list);
    }

    /**
     * 导出视频数据列表
     */
    @RequiresPermissions("system:date:export")
    @Log(title = "视频数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoDate videoDate)
    {
        List<VideoDate> list = videoDateService.selectVideoDateList(videoDate);
        ExcelUtil<VideoDate> util = new ExcelUtil<VideoDate>(VideoDate.class);
        util.exportExcel(response, list, "视频数据数据");
    }

    /**
     * 获取视频数据详细信息
     */
    @RequiresPermissions("system:date:query")
    @GetMapping(value = "/{xid}")
    public AjaxResult getInfo(@PathVariable("xid") Integer xid)
    {
        return success(videoDateService.selectVideoDateByXid(xid));
    }

    @GetMapping(value = "/getdatefufei/{xid}")
    public AjaxResult getInfoByXid(@PathVariable("xid") Integer xid){
        List<VideoDate> longVideos = videoDateService.selectLongVideoByXid(xid);
        return success(longVideos);
    }

    /**
     * 新增视频数据
     */
    @RequiresPermissions("system:date:add")
    @Log(title = "视频数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoDate videoDate)
    {
        return toAjax(videoDateService.insertVideoDate(videoDate));
    }

    /**
     * 修改视频数据
     */
    @RequiresPermissions("system:date:edit")
    @Log(title = "视频数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoDate videoDate)
    {
        return toAjax(videoDateService.updateVideoDate(videoDate));
    }

    /**
     * 删除视频数据
     */
    @RequiresPermissions("system:date:remove")
    @Log(title = "视频数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{xids}")
    public AjaxResult remove(@PathVariable Integer[] xids)
    {
        return toAjax(videoDateService.deleteVideoDateByXids(xids));
    }


    @GetMapping(value = "/getInfoByid/{id}")
    public AjaxResult getInfoByid(@PathVariable("id") Integer id){
        List<VideoDate> videoDateByid= videoDateService.selectVideoDateByid(id);
        redisTemplate.opsForList().leftPushAll("videoDateByid",videoDateByid);
        return AjaxResult.success(videoDateByid);
    }

    @GetMapping(value = "/getvideoxun/{liveId}")
    public AjaxResult getInfoByxid(@PathVariable("liveId") Integer liveId ){
        List<VideoDate> videoDates= videoDateService.selectVideoDateByxid(liveId);
        redisTemplate.opsForList().leftPushAll("videoDate",videoDates);
        return AjaxResult.success(videoDates);
    }

    @GetMapping(value = "/getvideoqing/{id}")
    public AjaxResult getInfoByqing(@PathVariable("id") Integer id){
        List<VideoDate> videoDateByid= videoDateService.selectVideoDateByid(id);
        redisTemplate.opsForList().leftPushAll("videoDateByid",videoDateByid);
        return AjaxResult.success(videoDateByid);
    }
}
